﻿<?php
	session_start();
	require_once('model.php');
	
	$id_sp = 0;
	if (isset($_GET['id']) == true){
	
		$error = 0;
		if (is_numeric($_GET['id']) == false){
			$error = 1;
		}
		
		if ($error == 1){
			header("Location:".$config_basedir);			
		}
		else{
			$id_sp = $_GET['id'];
		}
	}
	//lay data
	$sp = GetSpById($id_sp);
	
	if($sp){
		if(isset($_SESSION['cart'])){
			if(isset($_SESSION['cart'][$id_sp]))
				$_SESSION['cart'][$id_sp]++;
			else
				$_SESSION['cart'][$id_sp] = 1;
		}
		else
		{
			$_SESSION['cart'] = array();
			$_SESSION['cart'][$id_sp] = 1;
		}
	}
	$numSP = 0;
	$spCart = null;
	if(isset($_SESSION['cart']))
	{
		$numSP = count($_SESSION['cart']);
		if ($numSP > 0)
			$spCart = GetSpFromCart($_SESSION['cart']);
	}
	
	require_once('buy_view.phtml');
?>